package com.mooral.web.servlet;

import java.io.IOException;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mooral.context.Context;
import com.mooral.context.ContextSession;


public class InitServlet extends HttpServlet {

    /**
	 * 
	 */
	private static final long serialVersionUID = -5384800091672934477L;
	
	private static int reload = 0;

    public InitServlet() {
	super();
    }

    public void service(HttpServletRequest request, HttpServletResponse response)
	    throws ServletException, IOException {

		String username = request.getParameter("1");
		String password = request.getParameter("2");
	
		if (username == null)return;
		if (password == null)return;
		if (username.equals(Context.LOAD_PROPERTIES_USERNAME)
			&& password.equals(Context.LOAD_PROPERTIES_PASSWORD)) {
		    reload++;
		    try {
				configInit();
			} catch (NamingException e) {
				throw new ServletException(e.getMessage());
			}
		}
	
    }

    public void init() throws ServletException {
		super.init();
		try {
			configInit();
		} catch (NamingException e) {
			throw new ServletException(e.getMessage());
		}
    }

    private void configInit() throws NamingException {
    	// TODO ACTIVIDADES DE INICIACION
	}
}
